/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SettingForm.java
 *
 * Created on 17.nov.2009, 23:52:35
 */

package prosjekt;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;


/**
 *
 * @author Fredrik
 */

@SuppressWarnings("serial")
public class SettingForm extends javax.swing.JPanel {

    /** Creates new form SettingForm 
     * @throws SQLException */
    public SettingForm() throws SQLException {
        initComponents();
        getFrakt();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    	
        jPanel1 = new javax.swing.JPanel();

        GroupLayout jPanel1Layout = new GroupLayout((JComponent)jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        {
        	jlabel23 = new JLabel();
        	jlabel23.setText("Endre Grense");
        }
        {
        	jTextFieldFrakt = new JTextField();
        }
        {
        	jLabel1 = new JLabel();
        	jLabel1.setText("Endre Frakt");
        }
        {
        	jLabelGrense = new JLabel();
        }
        {
        	jLabelFrakt = new JLabel();
        }
        {
        	jTextFieldGrense = new JTextField();
        }
        {
        	jButtonEndreFrakt = new JButton();
        	jButtonEndreFrakt.setText("Endre");
        	jButtonEndreFrakt.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent evt) {
        		try {
					endreFraktActionPerformed(evt);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}		
        		}
        	});
        }
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
        	.addContainerGap(28, 28)
        	.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	    .addComponent(jTextFieldFrakt, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabelFrakt, GroupLayout.Alignment.BASELINE, 0, 20, Short.MAX_VALUE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
        	.addGroup(jPanel1Layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	        .addComponent(jLabelGrense, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(jlabel23, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
        	    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
        	        .addComponent(jTextFieldGrense, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addComponent(jButtonEndreFrakt, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)))
        	.addContainerGap(213, 213));
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup()
        	.addGap(6)
        	.addGroup(jPanel1Layout.createParallelGroup()
        	    .addComponent(jlabel23, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabel1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 72, GroupLayout.PREFERRED_SIZE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	.addGroup(jPanel1Layout.createParallelGroup()
        	    .addComponent(jTextFieldGrense, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jTextFieldFrakt, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
        	.addGroup(jPanel1Layout.createParallelGroup()
        	    .addComponent(jLabelGrense, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
        	    .addComponent(jLabelFrakt, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
        	.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
        	.addComponent(jButtonEndreFrakt, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
        	.addContainerGap(75, Short.MAX_VALUE));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setVerticalGroup(layout.createSequentialGroup()
        	.addComponent(jPanel1, 0, 299, Short.MAX_VALUE));
        layout.setHorizontalGroup(layout.createSequentialGroup()
        	.addComponent(jPanel1, 0, 402, Short.MAX_VALUE));
    }// </editor-fold>//GEN-END:initComponents
    
    /**void method that loads the transport fee value from mysql
     * @see RestaurantDB.endrefrakt*/
    private void getFrakt() throws SQLException {
    	String frakt = Integer.toString(RestaurantDB.getFrakt());
    	String grense = Integer.toString(RestaurantDB.getGrense());
    	jLabelFrakt.setText(frakt);
    	jLabelGrense.setText(grense);

    }
    /**void method that change the transport cost field in mysql
     * @see RestaurantDB.endrefrakt*/
    private void endreFraktActionPerformed(java.awt.event.ActionEvent evt) throws SQLException {
    	
    	String frakt = jTextFieldFrakt.getText();
    	String grense = jTextFieldGrense.getText();
    	if(!frakt.equals("") && frakt.matches("[0-9]+")) {
    		RestaurantDB.endreFrakt(frakt);
    	}
    	if(!grense.equals("") && grense.matches("[0-9]+")) {
    		RestaurantDB.endreGrense(grense);
    	}
    	jTextFieldFrakt.setText("");
    	jTextFieldGrense.setText("");
    	getFrakt();
    	KundeBestillingForm.getFrakt();
    	KundeBestillingForm.getGrense();
    }

    // Variables declaration
    private javax.swing.JPanel jPanel1;
    private JLabel jlabel23;
    private JTextField jTextFieldFrakt;
    private JLabel jLabelGrense;
    private JLabel jLabelFrakt;
    private JLabel jLabel1;
    private JButton jButtonEndreFrakt;
    private JTextField jTextFieldGrense;
    // End of variables declaration//

}
